package com.invengo.module_robot.ui.fragment.bookinfo;

import android.annotation.SuppressLint;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.invengo.module_robot.R;


/**
 * Create by Carson on 2021/12/22.
 * 展开 --- 收起 适配器
 */
public class OpenCloseAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private boolean mIsShowOnlyCount =true;
    private int mCount = 3;//设置最多展示几条数据

    public OpenCloseAdapter() {
        super(R.layout.item_book_info);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, String item) {
        helper.setText(R.id.itemLocation, item);
    }

    /**
     * 设置是否仅显示的条数
     * 默认全部显示
     */
    public void setShowOnlyThree(boolean isShowOnlyThree) {
        setShowOnlyCount(isShowOnlyThree, 3);
    }

    /**
     * 设置显示的条数
     */
    @SuppressLint("NotifyDataSetChanged")
    public void setShowOnlyCount(boolean isShowOnlyThree, int count) {
        mIsShowOnlyCount = isShowOnlyThree;
        mCount = count;
        notifyDataSetChanged();
    }

    /**
     * 获取项目计数
     *
     * @return int
     */
    @Override
    public int getItemCount() {
        return mIsShowOnlyCount ? Math.min(super.getItemCount(), mCount) : super.getItemCount();
    }
}
